angular.module('app.directive', [])
    .directive('errSrc',function(){
        return {
            link: function(scope, element, attrs) {
                if(attrs.src == undefined){
                    attrs.$set('src', attrs.errSrc);
                }
                element.bind('error', function() {
                    if (attrs.src != attrs.errSrc) {
                        attrs.$set('src', attrs.errSrc);
                    }
                });
            }
        }
    })
    .directive('fileModel', function ($parse) {
        return {
            restrict: 'A',
            link: function(scope, element) {
                element.bind('change', function(event){
                    //附件预览
                    scope.file = (event.srcElement || event.target).files[0];
                    scope.getFile(scope.file);
                });
            }
        };
    })
    .directive('stringHtml' , function(){
        return function(scope , el , attr){
            if(attr.stringHtml){
                scope.$watch(attr.stringHtml , function(html){
                    el.html(html || '');//更新html内容
                });
            }
        };
    });